/**
 * 数据操作服务
 */
export default class LoginService {
    constructor() {

    }

    /**
     * 获取列表  get接口示例
     * @param {*} options
     */
    async getLiveList(options) {
        return new Promise(function(resolve, reject) {
            $.ajax({
                type: "Get",
                url: `${API_PATH}/api/v1/login?platfrom=mobile&way=wechat&state=${options.state}&time=${new Date().getTime()}`,
                dataType: "json",
                data: options,
                success: function(result) {
                    resolve(result);
                },
                error: function() {
                    resolve({
                        code: 500,
                        message: "网络繁忙，请稍后再试"
                    });
                }
            });
        });
    }


    async getUser(token, id) {
        return new Promise(function(resolve, reject) {
            $.ajax({
                type: "Get",
                url: `${API_PATH}/api/v1/users/${id}`,
                dataType: "json",
                data: {a:1},
                beforeSend: function(request) {
                  request.setRequestHeader("Authorization", token);
              },
                success: function(result) {
                    resolve(result);
                },
                error: function() {
                    resolve({
                        code: 500,
                        message: "网络繁忙，请稍后再试"
                    });
                }
            });
        });
    }


    
    async saveUser(token, id,options) {
      return new Promise(function(resolve, reject) {
          $.ajax({
              type: "PUT",
              url: `${API_PATH}/api/v1/users/${id}`,
              dataType: "json",
              data: options,
              beforeSend: function(request) {
                request.setRequestHeader("Authorization", token);
            },
              success: function(result) {
                  resolve(result);
              },
              error: function() {
                  resolve({
                      code: 500,
                      message: "网络繁忙，请稍后再试"
                  });
              }
          });
      });
  }

}